package cn.gailvlun.gll.util;

import android.content.Context;

import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import cn.gailvlun.gll.BuildConfig;
import cn.gailvlun.gll.wxapi.WXEntryActivity;



public class WechatLogin extends BaseThirdLogin {

    private String AppId = BuildConfig.WECHAT_APP_ID;
    private IWXAPI iwxapi;

    public WechatLogin(Context context) {
        iwxapi = WXAPIFactory.createWXAPI(context, AppId, false);
        iwxapi.registerApp(AppId);
    }

    @Override
    public boolean isAppInstalled() {
        return iwxapi.isWXAppInstalled();
    }

    @Override
    public void login() {
        SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = "wechat_sdk_demo_test";
        iwxapi.sendReq(req);
    }

    @Override
    public void setOnLoginListener(OnLoginListener onLoginListener) {
        WXEntryActivity.mOnLoginListener = onLoginListener;
    }
}
